home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…eptember: Technology Seed / September 98 ADC Seed CD.toast / LaserWriter 8.6b5 Seed / Prerelease Docs / sample JPEGConverter / Source / Utilities.c < prev   
Encoding:
C/C++ Source or Header  |  1998-08-12  |  2.0 KB  |  82 lines  |  [TEXT/CWIE]

  1. /*
  2. *    File Name:        Utilities.c
  3. *
  4. *    Description:    Miscellaneous utilities for use with the sample JPEG converter.
  5. *
  6. *    Written by:        David Gelphman 04/03/98
  7. *
  8. *    Copyright:    © 1998 by Apple Computer Inc., All Rights Reserved.
  9. *
  10. *    Change History (most recent first):
  11. *
  12. *    04/03/98    DMG457    First version of this file.
  13. *
  14. */
  15.  
  16. #include "Utilities.h"
  17. #include "PSWriterErr.h"
  18.  
  19. OSStatus getHint(Collection hints, CollectionTag tag, long id, long hintSize, void *data)
  20. {
  21.     long itemSize;
  22.     OSStatus err;
  23.     
  24.     itemSize = hintSize;
  25.     err = GetCollectionItem(hints, tag, id, &itemSize, data);
  26.     if(!err && itemSize != hintSize) err = errHintWrongSize;
  27.     
  28.     return err;
  29. }
  30.  
  31. void *copyPStr(StringPtr dest, ConstStringPtr src, Size bufSize)
  32. /*    Copy the pascal String 'src' to 'dest' max size bufSize. Returning pointer after dest string.
  33.     If the Destination string is shorter than the source string, the string size is reduced appropriately.
  34.     Moved from a macro to a routine as we weren't updating the dest length byte
  35.     correctly:.
  36. */
  37. {
  38.     int len;
  39.     
  40.     /*    Figure out how many bytes to copy. If the buffer is
  41.         bigger than the Pascal String (minus the length byte)
  42.         then copy the whole string plus the length byte. Otherwise
  43.         just fill the buffer.
  44.     */
  45.     len = bufSize > *src ? *src + 1: bufSize;    
  46.     (void) memcpy(dest, src, len);
  47.     *dest = len - 1;                                // Update the length byte.
  48.     
  49.     return dest + len;
  50. }
  51.  
  52. void pNStrCat(StringPtr base, const Byte *more, Size baseSize)
  53. /*    Concatenate the pascal String 'more' to the back of 
  54.     the pascal String 'base'. This function will make sure
  55.     that the resulting Pascal string fits in a buffer with
  56.     'baseSize' bytes.
  57. */
  58. {
  59.     Size bytesToCopy = baseSize - *base - 1;
  60.     
  61.     if(*more < bytesToCopy) bytesToCopy = *more;
  62.     
  63.     if(bytesToCopy > 0){
  64.         bcopy(more + 1, afterPSTR(base), bytesToCopy);
  65.         *base += bytesToCopy;
  66.         }
  67. }
  68.  
  69. void CopyCtoPstr(StringPtr dst, char* src)
  70. {
  71.     unsigned char *firstP = dst++;
  72.     unsigned char count = 0;
  73.     
  74.     while((count < 255) && (*dst++ = *src++) != 0)
  75.         count++;
  76.     *firstP = count;
  77. }
  78.  
  79. void psDisposePtr(Ptr ptr){
  80.     if(ptr)
  81.         DisposePtr(ptr);
  82. }